#! /bin/sh -vx
# $Id$
# Copyright 2017 Karl Berry <tex-live@tug.org>
# Copyright 2011-2015 Peter Breitenlohner <tex-live@tug.org>
# You may freely use, modify and/or distribute this file.

BinDir=${BinDir:-.}
ExeExt=${ExeExt:-}
_omfonts=$BinDir/omfonts$ExeExt

# pre-generated test results in the repository are stored in LF
# but the output might be written in CRLF on some platform.
# if 'diff --strip-trailing-cr' is available, exploit it.
# (useful for tests on win32 binaries run on MSYS shell)
DIFF="diff"
$DIFF --strip-trailing-cr $0 $0 \
  && DIFF="diff --strip-trailing-cr" || echo

tests=tests

test -d $tests || mkdir -p $tests
rc=0

TEXMFCNF=$srcdir/../../kpathsea
OFMFONTS=./$tests
export TEXMFCNF OFMFONTS

$_omfonts -opl2ofm -verbose $srcdir/$tests/sample0-h $tests/sample0-h || rc=1

$_omfonts -opl2ofm -verbose $srcdir/$tests/sample0-h $tests/sample1-h || rc=2

$_omfonts -ofm2opl -verbose sample1-h $tests/sample1-h || rc=3

diff $srcdir/$tests/sample0-h.opl $tests/sample1-h.opl || rc=4

$_omfonts -ovp2ovf -verbose $srcdir/$tests/sample $tests/sample $tests/sample || rc=5

$_omfonts -ovf2ovp -verbose $tests/sample sample $tests/xsample.out || rc=6

diff $srcdir/$tests/sample.out $tests/xsample.out || rc=7

$_omfonts -ovp2ovf -verbose $srcdir/$tests/sample.ovp $tests/sample2.ovf || rc=8

$_omfonts -ovf2ovp -verbose $tests/sample2 sample2 >$tests/xsample2.out || rc=9

$DIFF $srcdir/$tests/sample.out $tests/xsample2.out || rc=10

exit $rc
